package com.mall.hadoop.job.sellstatic;

import java.io.IOException;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.collections.MapUtils;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 统计全国园所信息
 * @author tgy
 *
 */
@SuppressWarnings("unchecked")
public class SellStaticMap extends Mapper<LongWritable, Text, Text, IntWritable>{

	public static Logger logger = LoggerFactory.getLogger(SellStaticMap.class);
	
	@Override
	protected void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException {
		try{
			Map<String,Object> map = JSONObject.fromObject(value.toString());
			String p = MapUtils.getString(map, "province");
			String c = MapUtils.getString(map, "city");
			String a = MapUtils.getString(map, "area");
			context.write(new Text(p+"p"), new IntWritable(1));
			context.write(new Text(p+c+"c"), new IntWritable(1));
			context.write(new Text(p+c+a+"a"), new IntWritable(1));
		}catch(Exception e){
			logger.info("解析全国园所信息出现异常："+e.toString());
		}
	}
}











